$.fn.serializeObject = function()    
{    
   var o = {};    
   var a = this.serializeArray();    
   $.each(a, function() {    
       if (o[this.name]) {    
           if (!o[this.name].push) {    
               o[this.name] = [o[this.name]];    
           }    
           o[this.name].push(this.value || '');    
       } else {    
           o[this.name] = this.value || '';    
       }    
   });    
   return o;    
};  
$(function(){
	var id=localStorage.getItem("rowId");
	localStorage.removeItem("rowId");
	getMaterielById(id);
	$('.add').on('click',saveScene);
});


function saveScene(){
	var json={};
    json = $("#addDataFormHeader").serializeObject();
    json=JSON.stringify(json);
	if(checknull("employeeName") ){
		$.ajax({
			url: webUrl+'chwEmployee/updateChwEmployee.do',
			type:'post',
			data:{param:json}
		}).done(function(data){
			var result = data.bo;
			if(result==0){
				$.messager.confirm('提示 ', '修改成功！', function(r){
					$('.main_panel').load(webUrl+"public/page/employee/employeeQuery.html");
				});
			}else{
				$.messager.alert('提示 ', '修改失败！', 'info');
			}
		});
	}
}

function getMaterielById(id){
	$.ajax({
		url:webUrl+'chwEmployee/findChwCustomerById.notPermSc',
		type:'post',
		data:{id:id}
	}).done(function(data){
		var d = data.bo;
		//alert(JSON.stringify(d));
		$("#employeeName").val(d.employeeName);
		$("#employeeCard").val(d.employeeCard);
		$("#employeeId").val(d.employeeId);
		if(d.employeeSex=="男"){
			$("#radio1").attr("checked", "checked"); 
		}
		if(d.employeeSex=="女"){
			$("#radio2").attr("checked", "checked"); 
		}
		$("#employeeAge").val(d.employeeAge);
		$("#employeePhone").val(d.employeePhone);
		$("#bankAccountName").val(d.bankAccountName);
		$("#bankAccountNum").val(d.bankAccountNum);
		$("#employeeMail").val(d.employeeMail);
		$("#employeeQq").val(d.employeeQq);
		$("#employeeMarriage").val(d.employeeMarriage);
		$("#employeeQualification").val(d.employeeQualification);
		$("#employeeAddress").val(d.employeeAddress);
		$("#remark").val(d.remark);
		if(d.contractStartTime!=null){
			$('#contractStartTime').datebox('setValue',formatTime(d.contractStartTime));
		}
		if(d.contractEndtTime!=null){
			$('#contractEndtTime').datebox('setValue',formatTime(d.contractEndtTime));
		}
		if(d.departmentName!=null){
			$('#departmentName').combobox('select', ""+d.departmentName+"");
		}
		if(d.employeeJob!=null){
			$('#employeeJob').combobox('select', ""+d.employeeJob+"");
		}
		if(d.status!=null){
			$('#status').combobox('select', ""+d.status+"");
		}
	});
}